package DAO.impl;

import java.util.List;

import javax.persistence.Query;

import model.impl.Passenger;
import model.impl.Ticket;
import DAO.HibernateUtil;
import DAO.TicketDAO;
import DAO.impl.GenericDAOImpl;

public class TicketDAOImpl extends GenericDAOImpl<Ticket, Integer> implements
		TicketDAO {
	
	public List<Ticket> getAllTickets(Passenger passenger) {
		List<Ticket> tickets = null;
		try {
			HibernateUtil.beginTransaction();
			String sqlRequest = "SELECT t FROM Ticket t WHERE t.passenger = :givenPassenger";
			Query query = HibernateUtil.getSession().createQuery(sqlRequest).setParameter("givenPassenger", passenger);
			tickets = this.findMany(query);
			HibernateUtil.commitTransaction();
		} catch (Exception e) {
			HibernateUtil.rollbackTransaction();
            System.out.println("Error in getAllTickets");
            e.printStackTrace();
        }
		return tickets;
	}
}
